package org.space.ai.controller;

import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.HashMap;
import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/dataAI")

@CrossOrigin(origins = "*") // 允许来自
public class DataAIController {

    @Autowired
    private final ChatClient chatClient;

    @GetMapping("/contentVerification")
    public String contentVerification(@RequestParam("content") String content) {
        return chatClient.prompt().user(content).call().content();
    }


    @RequestMapping("/test")
    public String test(@RequestParam(value = "message") String message) {
        return message;
    }

    @RequestMapping("/chat")
    public String generate(@RequestParam(value = "message") String message) {
        String data = chatClient.prompt().user(message).call().content();
        System.out.println("DeepSeek:"+message+"; data:" + data);
        return data;
    }
    @RequestMapping(value = "/chats", produces = "text/html;charset=utf-8")
    public Flux<String> generates(@RequestParam(value = "message") String message) {
        Flux<String> data = chatClient.prompt().user(message).stream().content();
        System.out.println("DeepSeek:"+message+"; data:" + data);
        return data;
    }
}
